<%@page import="efrei.ngo.entity.Floor"%>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
	pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<%@page import="efrei.ngo.util.GeneralUnil"%>
<%@page import="efrei.ngo.entity.ItemDetail"%>
<%@page import="efrei.ngo.util.DatabaseAccess"%>
<%@page import="java.util.ArrayList"%>

<html>
<%
	DatabaseAccess.connectToDB();
	String postID = request.getParameter("postID");
	System.out.println("post ID:\t" + postID);
	if (postID == null||postID == "") {
		response.sendRedirect("ForumList.jsp");
		return;
	}
	ItemDetail post = DatabaseAccess.dbGetPostD(postID);
	if (post == null) {
		response.sendRedirect("ForumList.jsp");
		return;
	}

	ArrayList<Floor> floorList = DatabaseAccess.dbGetFloorList(postID);
	DatabaseAccess.endConnectionToDB();
	
	String HTMLPostID="<input type=\"hidden\" id=\"postID\" name=\"postID\" value=\""+postID+"\"/>";

	String htmlEveryFloor = "";
	
	for (int i = 1, len = floorList.size(); i <= len; i++) {
		Floor tempFloor=floorList.get(i-1);
		String context;
		if(tempFloor.getToSomebody()==null||tempFloor.getToSomebody().getU_id()==8){
			context="\t\t"+tempFloor.getContext();					
		}else{
			//<strong>Re:User1</strong><br/>
			context="<strong>Re:"+tempFloor.getToSomebody().getUsername()+"</strong><br/>\t\t"+tempFloor.getContext();
		}
		
		htmlEveryFloor += "<tr>"
				+ "<td width=\"30%\" rowspan=\"3\" align=\"center\" class=\"td_c_edge_body\"style=\"font-size:xx-large\">"+tempFloor.getOwner().getUsername()+"</td>"
				+ "<td width=\"50%\" style=\"background-color: #777;color:WHITE\" align=\"right\">"+GeneralUnil.changeDateToString(tempFloor.getPostDate())+"</td>"
				+ "<td width=\"20%\" align=\"right\" style=\"background-color: #BBB;\">"
				+ i
				+ "  floor</td>"
				+ "</tr>"
				+ "<tr>"
				+ "<td height=\"125\" colspan=\"2\" style=\"background-color:#FFF\" align=\"left\">"+context+"</td>"
				+ "</tr>" + "<tr>"
				+ "<td colspan=\"2\" style=\"background-color: #777;color:WHITE\" align=\"right\">reply</td>"
				+ "</tr>\n";
	}
		%>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Forum</title>
<style type="text/css">
textarea {
    resize: none;
}
.td_black{
	font: bold 11px "Trebuchet MS", Verdana, Arial, Helvetica,sans-serif;
	color:#FFF;
	border-right: 1px solid #C1DAD7;
	border-bottom: 1px solid #C1DAD7;
	border-top: 1px solid #C1DAD7;
	letter-spacing: 2px;
	text-transform: uppercase;
	text-align: left;
	padding: 6px 6px 6px 12px;
	background:#666 no-repeat;
}

.td_toC {
	border-right: 1px solid #C1DAD7;
	border-bottom: 1px solid #C1DAD7;
	background: #fff;
	font-size:11px;
	padding: 6px 6px 6px 12px;
	color: #4f6b72;
}

td.td_c_edge{
    -moz-border-radius:5px 0px 0px 0px;
    -webkit-border-top-left-radius:5px;
    border-top-left-radius:5px;
    -moz-border-radius:0px 0px 0px 5px;
    -webkit-border-bottom-left-radius:5px;
    border-bottom-left-radius:5px;
    
	background:-webkit-gradient(
        linear,
        left bottom,
        left top,
        color-stop(0.39, rgb(85,85,85)),
        color-stop(0.7, rgb(105,105,105))
        );
    background:-moz-linear-gradient(
        center bottom,
        rgb(85,85,85) 39%,
        rgb(105,105,105) 70%
        );
}

td.td_c_edge_body{
    -moz-border-radius:5px 0px 0px 0px;
    -webkit-border-top-left-radius:5px;
    border-top-left-radius:5px;
    -moz-border-radius:0px 0px 0px 5px;
    -webkit-border-bottom-left-radius:5px;
    border-bottom-left-radius:5px;
    
 	background:-webkit-gradient(
        linear,
        left bottom,
        left top,
        color-stop(0.39, rgb(189,189,189)),
        color-stop(0.7, rgb(224,224,224))
        );
    background:-moz-linear-gradient(
        center bottom,
        rgb(189,189,189) 39%,
        rgb(224,224,224) 70%
        );
}

</style>
<link rel="stylesheet" href="../css/button.css">
<link rel="stylesheet" href="../css/custom-theme/jquery-ui-1.8.18.custom.css">
<link rel="stylesheet" href="../css/custom-theme/jquery.ui.all.css">
<!-- <link rel="stylesheet" href="../css/table_style_2.css"> -->
<script type="text/javascript" src="../js/jquery-1.7.1.js"></script>
<script type="text/javascript" src="../js/js4forum.js"></script>
</head>
<body>
	<%=HTMLPostID%>
	<h2>Forum</h2>
	<div align="right" style="width:90%">
		<label> <input type="submit" name="forNewPost" id="forNewPost"
			value="New Post">
		</label>
	</div>
	<h3 style="width:95%">TITLE:    <%=post.getTitleName()%></h3>
	<div align="center">
<table style="width:95%;border:1;width:90%;cellpadding:0;cellspacing:0">
	<thead>
		<tr>
			<td width="30%" rowspan="3" class="td_c_edge" style="color:#FFF">
			<div align="center" style="font-size:xx-large"><%=post.getOwner().getUsername()%></div>
		  </td>
      		<td width="50%" style="background-color: #555;color:WHITE" align="right"><%=GeneralUnil.changeDateToString(post.getPostDate())%></td>
			<td width="20%" align="right" style="background-color: #999">HEAD</td>
		</tr>
		<tr>
			<td height="125" colspan="2" style="color:BLACK;background-color:#FFF" align="left"><%=post.getTextContent()%></td>
		</tr>
		<tr>
		  <td colspan="2" align="right" style="background-color: #555;color:WHITE">reply</td>
		</tr>
	</thead>
	<tbody>
		<%=htmlEveryFloor%>
		</tbody>
</table>
</div>
    <hr>
    <div>
    	<div align="right" style="width:95%">
      		<textarea name="textReply" id="textReply" style="border:inset;height:100px;width:80%"></textarea>
      	</div>
      <div align="right" style="width:95%"><input type="button" class="button" onClick="onclick_reply();" value="Reply" style="font-size:14px;height:35px;width:80px"></div>
    </div>
</body>
</html>